<!--
  Created by IntelliJ IDEA.
  User: Dai
  Date: 2018/5/14
  Time: 15:40
  To change this template use File | Settings | File Templates.
-->
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">修改密码</h4>
</div>
<form id="defaultForm" method="post" class="form-horizontal" action="/system/menu_save">
    <div class="modal-body">
        <div class="form-group">
            <label class="col-lg-3 control-label">密码：</label>
            <div class="col-lg-5">
                <input type="password" class="form-control" name="password" placeholder="请输入密码"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-3 control-label">确认：</label>
            <div class="col-lg-5">
                <input type="password" class="form-control" placeholder="请再输一次" name="checkPassword"/>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>

<script>
    $('#defaultForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            password: {
                validators: {
                    notEmpty: {
                        message: '密码不能为空'
                    },
                    regexp: {
                        regexp: /^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&*]+$)(?![\d!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/,
                        message: '密码必须含有数字、字母、特殊字符，不能有中文'
                    }
                }
            },
            checkPassword: {
                validators: {
                    notEmpty: {
                        message: '密码不能为空'
                    },
                    regexp: {
                        regexp: /^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&*]+$)(?![\d!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/,
                        message: '密码必须含有数字、字母、特殊字符，不能有中文'
                    }
                }
            }
        }
    }).on("success.form.bv", function (e) {
        // 阻止默认提交事件
        e.preventDefault();
        // 获取form表单
        var $form = $(e.target);
        // Get the BootstrapValidator instance
        var bv = $form.data('bootstrapValidator');
        console.log($('#defaultForm').serialize());

        var password = $("input[name='password']").val().trim();
        var checkPassword = $("input[name='checkPassword']").val().trim();
        if (password != checkPassword) {
            alert("请确认密码一致");
            return;
        }
        $.post("system/password_save", {password: password}, function (data) {
            window.location.href = "/logout";
        });
    });
</script>